---
title: "FALL Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
social: [ "twitter", "facebook", "menu"]
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(DT)
library(rpivotTable)
library(ggplot2)
library(plotly)
library(plyr)
library(dplyr)
library(openintro)
library(highcharter)
library(ggvis)
library(devtools)
library(coronavirus)
library(tidyr)
library(plyr)
library(maps)
library(mapdata)
library("sf")
library("cartogram")
library("reshape2")
library("cartography")
library(readxl)
```
```{r}
setwd("~/Desktop/TP R")
#############
data(coronavirus)
###########@
`%>%` <- magrittr::`%>%`
###########
df_monde <- coronavirus %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(country) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death - recovered) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active)
)
df_monde_date <- coronavirus %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death - recovered) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active)
)
```
```{r}
mycolors <- c("blue", "#FFC125", "darkgreen", "darkorange")
```
COVID 19 MONDIAL
=====================================
Row
-------------------------------------
### CAS CONFIRMES
```{r}
########https://fontawesome.com/icons?m=free
valueBox(max(df_monde$confirmed_cum),
icon = "fa-user", color = "blue")
```
### CAS GUERIS
```{r}
valueBox(max(df_monde$recovered_cum),
icon = "fa-user-plus", color="green")
```
### CAS MORTS
```{r}
valueBox(max(df_monde$death_cum),
icon = 'fa-user-slash', color = "red")
```
### CAS ACTIVES
```{r}
valueBox(max(df_monde$active_cum),
icon = 'fa-calendar-plus', color="orange")
```
Row
-------------------------------
### Distribution COVID 19 MONDIAL
```{r}
df_monde_date %>%
plot_ly(x = ~ date,
y = ~ active_cum,
name = 'Cas actifs',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace(y = ~ death_cum,
name = "Cas morts",
fillcolor = '#E41317') %>%
add_trace(y = ~recovered_cum,
name = 'Cas guéris',
fillcolor = 'forestgreen') %>%
layout(title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "NOMBRE DES CAS"),
xaxis = list(title = "Source: Package R (coronavirus) produit par Cheikh FALL"))
```
### CAS CONFIRMES PAR PAYS
```{r}
plot_ly(data = df_monde,
type= "treemap",
values = ~confirmed,
labels= ~ country,
parents= ~"Cas confirmés",
domain = list(column=0),
name = "CAS CONFIRMES",
textinfo="label+value+percent parent")
```
Map
========================================
### Map
```{r}
world<- st_read("~/Desktop/TP/exercice3/data/world.shp",stringsAsFactors = F)
ex=read_xlsx("~/Desktop/TP/exercice3/data/excel.xlsx")
world<- merge(x = world, y = ex, by.x = "ID", by.y = "ID", all.x=T)
world<- merge(x = world, y =df_monde, by.x = "Pays", by.y = "country", all.x=T) # CAS CONFIRMES
world=world[,-2]
world=world %>% filter(!is.na(world$Pays))
world=world %>% filter(!is.na(world$confirmed))
world=world %>% filter(!is.na(world$geometry))
par(mfrow=c(1,1))
par(mar = c(0.5,0.5,1.5,0.5)) # Ajuster les marges
plot(st_geometry(world),col="lightblue",border="white") # Fond de carte de la région Occitanie
propSymbolsLayer(x = world, var = "confirmed", # Carte en figurés proportionnels
symbols = "circle", col = "red",
legend.pos = "right", border = "grey",
legend.title.txt = "CAS CONFIMES",
legend.style = "c")
top <- sort(data.frame(world)[,"confirmed"], decreasing = TRUE)
labelLayer(x = world[data.frame(world)[,"confirmed"] %in% top[1:30],], txt = "Pays", halo=TRUE, cex = 0.5, col= "#000000", bg = "#FFFFFF50", overlap = FALSE) # Nommer les 15 premières villes en nombre d'actifs
title("CARTOGRAPHIE DU COVID 19 AU MONDE")
```
### Cartographie du COVID 19 dans la zone UEMOA
```{r}
world<- st_read("~/Desktop/TP/exercice3/data/world.shp",stringsAsFactors = F)
ex=read_xlsx("~/Desktop/TP/exercice3/data/excel.xlsx")
world<- merge(x = world, y = ex, by.x = "ID", by.y = "ID", all.x=T)
world<- merge(x = world, y =df_monde, by.x = "Pays", by.y = "country", all.x=T) # CAS CONFIRMES
world=world[,-2]
world=world %>% filter(!is.na(world$Pays))
world=world %>% filter(!is.na(world$confirmed))
uemoa=world[world$Pays=="Senegal" | world$Pays=="Togo"| world$Pays=="Niger" | world$Pays=="Benin" | world$Pays=="Mali" | world$Pays=="Cote d'Ivoire" | world$Pays=="Guinin" | world$Pays=="Burkina Faso", ]
par(mfrow=c(1,1))
par(mar = c(0.5,0.5,1.5,0.5)) # Ajuster les marges
plot(st_geometry(uemoa),col="lightblue",border="white") # Fond de carte de la région Occitanie
plot(st_geometry(uemoa),col="lightblue",border="white") # Fond de carte de la région Occitanie
propSymbolsLayer(x =uemoa, var = "confirmed", # Carte en figurés proportionnels
symbols = "circle", col = "red",
legend.pos = "right", border = "grey",
legend.title.txt = "CAS CONFIMES",
legend.style = "c")
top <- sort(data.frame(uemoa)[,"confirmed"], decreasing = TRUE)
labelLayer(x = uemoa[data.frame(uemoa)[,"confirmed"] %in% top[1:8],], txt = "Pays", halo=TRUE, cex = 0.5, col= "#000000", bg = "#FFFFFF50", overlap = FALSE) # Nommer les 15 premières villes en nombre d'actifs
title("CARTOGRAPHIE DU COVID 19 UEMOA")
```
COVID 19 UEMOA
========================================
```{r}
#############
uemoa=world[world$Pays=="Senegal" | world$Pays=="Togo"| world$Pays=="Niger" | world$Pays=="Benin" | world$Pays=="Mali" | world$Pays=="Cote d'Ivoire" | world$Pays=="Guinea-Bissau" | world$Pays=="Burkina Faso", ]
######################
##############
uemoa_date=coronavirus[coronavirus$country=="Senegal" | coronavirus$country=="Togo"| coronavirus$country=="Niger" | coronavirus$country=="Benin" | coronavirus$country=="Mali" | coronavirus$country=="Cote d'Ivoire" | coronavirus$country=="Guinea-Bissau" | coronavirus$country=="Burkina Faso", ]
###########
uemoa_date <- uemoa_date %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death - recovered) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active)
)
##############
uemoa$active=uemoa$confirmed-uemoa$death-uemoa$recovered
uemoa$death_cum=cumsum(uemoa$death)
uemoa$recovered_cum=cumsum(uemoa$recovered)
uemoa$confirmed_cum=cumsum(uemoa$confirmed)
uemoa$active_cum=cumsum(uemoa$active)
############
uemoa_date$active=uemoa_date$confirmed-uemoa_date$death-uemoa_date$recovered
uemoa_date$death_cum=cumsum(uemoa_date$death)
uemoa_date$recovered_cum=cumsum(uemoa_date$recovered)
uemoa_date$confirmed_cum=cumsum(uemoa_date$confirmed)
uemoa_date$active_cum=cumsum(uemoa_date$active)
#################
uemoa_date1=coronavirus[coronavirus$country=="Senegal" | coronavirus$country=="Togo"| coronavirus$country=="Niger" | coronavirus$country=="Benin" | coronavirus$country=="Mali" | coronavirus$country=="Cote d'Ivoire" | coronavirus$country=="Guinea-Bissau" | coronavirus$country=="Burkina Faso", ]
```
Row
-------------------------------
### CAS CONFIRMES
```{r}
##########
valueBox(sum(uemoa$confirmed),
icon = "fa-user", color="blue")
```
### CAS GUERIS
```{r}
valueBox(sum(uemoa$recovered),
icon = "fa-user-plus", color="green")
```
### CAS MORTS
```{r}
valueBox(sum(uemoa$death),
icon = 'fa-user-slash', color = "red")
```
### CAS ACTIVES
```{r}
valueBox(sum(uemoa$active),
icon = 'fa-calendar-plus', color="orange")
```
Row
-------------------------------
### Cas confirmés par pays
```{r}
plot_ly(data =uemoa,
type= "treemap",
values = ~confirmed,
labels= ~ Pays,
parents= ~"Cas confirmés",
domain = list(column=0),
name = "CAS CONFIRMES",
textinfo="label+value+percent parent")
```
### Histogramme des cas confirmés, décès et gueris par pays
```{r}
##############
uemoa_date1=uemoa_date1[uemoa_date1$cases>0,]
p=ggplot(uemoa_date1, aes(country, cases, fill = type)) +
geom_bar(stat="identity", position = "dodge") +theme_minimal()
p + scale_fill_manual(values=c('blue','red', 'green'))
```
Row
-------------------------------
### Evolution des cas confirmés, décès, actives et gueris par pays
```{r}
##############
uemoa_date=uemoa_date[uemoa_date$confirmed>0,]
fig <- plot_ly(
type = "scatter",
x = uemoa_date$date,
y = uemoa_date$confirmed,
name = 'Cas confirmés',
mode = "lines",
line = list(
color = 'blue'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = uemoa_date$date,
y = uemoa_date$death,
name = 'Cas morts',
mode = "lines",
line = list(
color = 'red'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = uemoa_date$date,
y = uemoa_date$active,
name = 'Cas en traitement',
mode = "lines",
line = list(
color = 'orange'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = uemoa_date$date,
y = uemoa_date$recovered,
name = 'Nombre de guéris',
mode = "lines",
line = list(
color = 'green'
))
fig <- fig %>%
layout(
title = "",
xaxis = list(
type = 'date',
tickformat = "%d %B (%a)
%Y"
))
fig
```
### Cumul des cas confirmés, décès et gueris par pays
```{r}
##############
uemoa_date1=uemoa_date1[uemoa_date1$cases>0,]
fig <- plot_ly(uemoa_date, x = ~date, y = ~confirmed_cum, type = 'scatter', mode = 'lines', name = "Cas confirmés")
fig <- fig %>% add_trace(y = ~active_cum, name = 'Cas en traitement')
fig <- fig %>% add_trace(y = ~recovered_cum, name = 'Cas guéris')
fig <- fig %>% add_trace(y = ~death_cum, name = 'Nombre de morts')
fig <- fig %>% layout(legend =1)
fig
```
COVID19 SENEGAL
========================================
```{r}
#############
SEN=world[world$Pays=="Senegal", ]
######################
##############
SEN=coronavirus[coronavirus$country=="Senegal", ]
###########
SEN <- SEN %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death - recovered) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active)
)
##############
SEN$active=SEN$confirmed-SEN$death-SEN$recovered
SEN$death_cum=cumsum(SEN$death)
SEN$recovered_cum=cumsum(SEN$recovered)
SEN$confirmed_cum=cumsum(SEN$confirmed)
SEN$active_cum=cumsum(SEN$active)
```
Row
-------------------------------
### CAS CONFIRMES
```{r}
##########
valueBox(sum(SEN$confirmed),
icon = "fa-user", color="blue")
```
### CAS GUERIS
```{r}
valueBox(sum(SEN$recovered),
icon = "fa-user-plus", color="green")
```
### CAS MORTS
```{r}
valueBox(sum(SEN$death),
icon = 'fa-user-slash', color = "red")
```
### CAS ACTIVES
```{r}
valueBox(sum(SEN$active),
icon = 'fa-calendar-plus', color="orange")
```
Row
-------------------------------
### Evolution des cas confirmés, décès, actives et gueris par pays
```{r}
##############
uemoa_date=SEN[SEN$confirmed>0,]
fig <- plot_ly(
type = "scatter",
x = SEN$date,
y = SEN$confirmed,
name = 'Cas confirmés',
mode = "lines",
line = list(
color = 'blue'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = SEN$date,
y = SEN$death,
name = 'Cas morts',
mode = "lines",
line = list(
color = 'red'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = SEN$date,
y = SEN$active,
name = 'Cas en traitement',
mode = "lines",
line = list(
color = 'orange'
))
fig <- fig %>%
add_trace(
type = "scatter",
x = SEN$date,
y = SEN$recovered,
name = 'Nombre de guéris',
mode = "lines",
line = list(
color = 'green'
))
fig <- fig %>%
layout(
title = "",
xaxis = list(
type = 'date',
tickformat = "%d %B (%a)
%Y"
))
fig
```
### Cumul des cas confirmés, décès et gueris au SENEGAL
```{r}
##############
uemoa_date1=uemoa_date1[uemoa_date1$cases>0,]
fig <- plot_ly(uemoa_date, x = ~date, y = ~confirmed_cum, type = 'scatter', mode = 'lines', name = "Cas confirmés")
fig <- fig %>% add_trace(y = ~active_cum, name = 'Cas en traitement')
fig <- fig %>% add_trace(y = ~recovered_cum, name = 'Cas guéris')
fig <- fig %>% add_trace(y = ~death_cum, name = 'Nombre de morts')
fig <- fig %>% layout(legend =1)
fig
```
Data Table
========================================
```{r}
datatable(coronavirus,
caption = "Failure Data",
rownames = T,
filter = "top",
options = list(pageLength = 25))
```
Pivot Table
=========================================
```{r}
rpivotTable(df_monde,
aggregatorName = "count",
cols= "confirmed",
rows = "country",
rendererName = "Heatmap")
```